﻿//-----------------------------------------------------------------------
// <copyright file="GoatFieldColorRGBA.cs" company="Nathan Miller">
// Copyright (c) Nathan Miller.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
//-----------------------------------------------------------------------
namespace GoatGen.Object
{
    using System;

    /// <summary>
    /// RGBA color field.
    /// </summary>
    public class GoatFieldColorRGBA : GoatField
    {
        #region Constants - Private

        /// <summary>
        /// Size of the array we are expecting.
        /// </summary>
        private const int ArraySize = 4;

        #endregion

        #region Constructor

        /// <summary>
        /// Constructor for a field.
        /// </summary>
        /// <param name="name">Name of the field.</param>
        /// <param name="properties">Properties for the field. Min, max, etc. Each field type defines
        /// the properties that it supports.</param>
        public GoatFieldColorRGBA(string name, GoatFieldProperties properties) :
            base(name, properties)
        {
            this.ParseDefault();
        }

        #endregion

        #region Properties - Public

        /// <summary>
        /// Gets the default values for the color. Always length 4.
        /// </summary>
        public byte[] Default
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets the C# type of the field.
        /// </summary>
        public override Type Type
        {
            get
            {
                return typeof(byte[]);
            }
        }

        #endregion

        #region Methods - Private

        /// <summary>
        /// Parse the default color value.
        /// </summary>
        private void ParseDefault()
        {
            byte[] value = this.ParseByteArray(GoatFieldConstants.DefaultKey, ArraySize);
            if (value != null)
            {
                this.Default = value;
                return;
            }

            this.Default = new byte[ArraySize];

            this.Default[0] = 255;
            this.Default[1] = 255;
            this.Default[2] = 255;
            this.Default[3] = 255;
        }

        #endregion
    }
}